package org.xin.security.service.impl;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.xin.common.util.XinUtil;
import org.xin.framework.base.service.impl.IBaseServiceImpl;
import org.xin.security.mapper.SysRolePermissionMapper;
import org.xin.security.pojo.entity.SysRolePermission;
import org.xin.security.service.ISysRolePermissionService;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 系统模块-菜单安全表 服务实现类
 * </p>
 *
 * @author: xin
 * @date: Create in 2021-10-08
 */
@Slf4j
@Service
public class SysRolePermissionServiceImpl extends IBaseServiceImpl<SysRolePermission, SysRolePermissionMapper> implements ISysRolePermissionService {
    @Override
    public List<SysRolePermission> selectByRoleId(String roleId, Integer permissionType) {
        lambdaQueryWrapper()
                .eq(SysRolePermission::getSysRoleId, roleId)
                .eq(SysRolePermission::getPermissionType, permissionType);
        return baseMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public Set<String> selectPermissionByRoleId(Set<String> permissions, String roleId, Integer permissionType) {
        selectByRoleId(roleId, permissionType).forEach(rolePermission -> {
            if (XinUtil.noNull(rolePermission.getPermission())) {
                permissions.add(rolePermission.getPermission());
            }
        });
        return permissions;
    }
}
